package com.hexb.smh.entity.view;

import com.hexb.core.utils.MapBuilder;
import com.hexb.smh.service.IConfigService;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.Getter;
import lombok.Setter;

import java.math.BigDecimal;
import java.util.Map;

/**
 * @author : hexb
 */
@Data
public class ProductSumView {

    @ApiModelProperty("固定成本合计")
    private BigDecimal fixedCostTotal;

    @ApiModelProperty("可变成本合计")
    private BigDecimal volatileCostTotal;

    @ApiModelProperty("其它成本合计")
    private BigDecimal otherCostTotal;

    @ApiModelProperty("市场价(原价)合计")
    private BigDecimal marketTotal;

    @ApiModelProperty("可变成本率=套餐固定成本合计÷套餐成交价x100")
    public BigDecimal getVolatileRate(BigDecimal dealPrice) {
        return volatileCostTotal
                .divide(dealPrice, IConfigService.SCALE, IConfigService.ROUND_TYPE);
    }

    @ApiModelProperty("固定成本率=套餐变动成本合计÷套餐成交价x100")
    public BigDecimal getFixedRate(BigDecimal dealPrice) {
        return fixedCostTotal
                .divide(dealPrice, IConfigService.SCALE, IConfigService.ROUND_TYPE);
    }

    @ApiModelProperty("其它成本率=套餐其它成本合计÷套餐成交价x100")
    public BigDecimal getOtherRate(BigDecimal dealPrice) {
        return otherCostTotal
                .divide(dealPrice, IConfigService.SCALE, IConfigService.ROUND_TYPE);
    }

    @ApiModelProperty("套餐折扣率=套餐成交价÷套餐原价合计x100")
    public BigDecimal getDiscountRate(BigDecimal dealPrice) {
        //TODO:是否判断成交价高于市场价的情况
        return dealPrice
                .divide(marketTotal, IConfigService.SCALE, IConfigService.ROUND_TYPE);
    }

    public Map<String, BigDecimal> getJSELContext(BigDecimal dealPrice) {
        return MapBuilder.<String, BigDecimal>create()
                .build("A", getFixedRate(dealPrice))
                .build("B", getVolatileRate(dealPrice))
                .build("C", getOtherRate(dealPrice))
                .build("D", getDiscountRate(dealPrice))
                .map();
    }

}
